﻿using Kingdee.BOS.Util;
using RK.Model.FanWei;
using RK.Model.Ronma;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.Tools
{
    public class InvokeHelper
    {
        public static string Post(string soTokenUrl)
        {
            HttpClient httpClient = new HttpClient();
            string str = httpClient.AsyncRequest(soTokenUrl);
            return str;
        }
        public static FlowChart Post(string esbUrl, string appkey, string workcode)
        {
            HttpClient httpClient = new HttpClient();
            string str = httpClient.AsyncRequest(esbUrl, appkey, workcode);
            FlowChart result = JsonUtil.DeserializeObject<FlowChart>(str);
            return result;
        }

        public static DBResult Post(string url, string jsonStr, string appkey, string workcode, int requestId)
        {
            //HttpClient httpClient = SingletonHttpClient.GetInstance();
            HttpClient httpClient = new HttpClient();
            httpClient.appkey = appkey;
            httpClient.workcode = workcode;
            string str = httpClient.AsyncRequest(url, jsonStr, appkey, workcode, requestId);
            ////解析返回结果
            //TestResult result = JsonUtil.DeserializeObject<TestResult>(str);
            DBResult result = JsonUtil.DeserializeObject<DBResult>(str);
            //result.Code = OAResultConstant.SUCCESS;
            //result.ErrMsg = "同步成功！测试固定返回结果！" + url;
            //JSONObject obj = new JSONObject();
            //obj.Add("requestid", "oaId");
            //result.Data = obj;
            return result;
        }

        public static OAResult Post(string url, string jsonStr, string appkey, string workcode, int requestId, string operationName)
        {
            if (operationName == "撤销")
            {
                if (requestId <= 0)
                {
                    return new OAResult() { Code = OAResultConstant.SUCCESS };
                }
                url = url + $"?requestId={requestId}";
            }
            //HttpClient httpClient = SingletonHttpClient.GetInstance();
            HttpClient httpClient = new HttpClient();
            httpClient.appkey = appkey;
            httpClient.workcode = workcode;
            string str = httpClient.AsyncRequest(url, jsonStr, appkey, workcode, requestId);
            ////解析返回结果
            //TestResult result = JsonUtil.DeserializeObject<TestResult>(str);
            OAResult result = JsonUtil.DeserializeObject<OAResult>(str);

            if (operationName == "反审核" && result.msg.EqualsIgnoreCase("ok"))
            {
                result.Code = OAResultConstant.SUCCESS;
            }
            //result.Code = OAResultConstant.SUCCESS;
            //result.ErrMsg = "同步成功！测试固定返回结果！" + url;
            //JSONObject obj = new JSONObject();
            //obj.Add("requestid", "oaId");
            //result.Data = obj;
            return result;
        }
    }
}
